<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>await</title>
</head>
<body>
  
  <!-- <script>
    async function main() {
      let p = new Promise( (resolve, reject) => {
        resolve('OK');
      })

      // 1. 右侧为 Promise 的情况。
      let res = await p
      console.log(res);
    }
    main()
  </script> -->

  <!-- <script>
    async function main() {
      let p = new Promise( (resolve, reject) => {
        resolve('OK');
      })

      // // 2. 右侧为其它类型的数据
      let res2 = await 20;
      console.log(res2);
    }
    main()
  </script> -->


<script>
  async function main() {
    let p = new Promise( (resolve, reject) => {
      reject('error')
    })

    // 3. 如果 Promise 是失败的状态
    try {
      await p;
    }catch(e) {
      console.log(e);
    }
  }
  main()

</script>


</body>
</html>